package imagekeeper.data;

import java.sql.Connection;
import java.sql.SQLException;
//import imagekeeper.data.mapping.*;


class SqlStatementSearchImages extends SqlStatement {
    public SqlStatementSearchImages(Connection con) throws SQLException {
        StringBuilder sqlRequest = new StringBuilder("SELECT DISTINCT image.* FROM image, image_tag, tagged_image ");
        sqlRequest.append("WHERE !privacy AND image.id = tagged_image.image_id AND image_tag.id = tagged_image.image_tag_id ");
        sqlRequest.append("AND (INSTR(LOWER(?), LOWER(image_tag.tag_value)) > 0 OR INSTR(LOWER(image_tag.tag_value), LOWER(?)) > 0) ");
        sqlRequest.append("LIMIT ?, ?;");
        statement = con.prepareCall(sqlRequest.toString());
    }
    
    public void setSearchKey(String key) throws SQLException {
        statement.setString(1, key);
        statement.setString(2, key);
    }
    
    public void setResultLimits(int offset, int count) throws SQLException {
        statement.setInt(3, offset);
        statement.setInt(4, count);
    }
    
    public void setUserId(int id) {
        // using to include private images of current user into results
    }
}
